const app = getApp()
Page({
	data: {
		next:false,
		dataList:[],
		baseUrl: app.globalData.baseUrl,
		page:1,
		size:6,
		type:1,
		activeTab:0,
		state:0,
		isLaunch:2,
		totel:'',
		keywords:'',
		changetype:'',
		changestate:'',
		dataactive:0
	},
	onLoad(options) {
		if(options.type){
			let _type = Number(options.type)
			this.setData({
				activeTab:_type,
				type:_type+1,
			})
		}
		if(options.keywords){
			this.setData({
				keywords:options.keywords
			})
		}
		this.getList()
	},
	tabChange(e) {
		let type = Number(e.detail.index) + 1
		console.log(type)
		this.setData({
			dataList:[],
			page:1,
			type:type,
		})
		this.getList()
	},
	getList(){
		app.indexApi.approvalList({
			page:this.data.page,
			size:8,
			keywords:this.data.keywords,
			type:this.data.type
		}).then(res => {
			if (res.code == 0) {
				let _data = res.data;
				
				var sc=_data.total/8
					if(_data.total%8>0){
						sc+=1
					}
					var list=[]
					this.data.dataList.forEach(item => {
						list.push(item)
					});
					_data.forEach(item => {
						list.push(item)
					});
				this.setData({
					dataList:list,
					totel:sc
				})
			}
		})
	},
	search(){
		this.setData({
			page:1,
			dataList:[]
		})
		this.getList()
	},
	changeType(e){
		let type = e.currentTarget.dataset.type
		if(type != 1){
			this.setData({
				changestate:-1
			})
		}
		this.setData({
			changetype:type
		})
	},
	changeState(e){
		let state = e.currentTarget.dataset.state
		
		this.setData({
			changestate:state
		})
		
	},
	changeSubmit(){
		console.log(this.data.changetype)
		this.setData({
			state:this.data.changestate,
			type:this.data.changetype,
			page:1,
			dataList:[],
			next:false
		})
		this.getList()
	},
	changeList(e){
		let state = e.currentTarget.dataset.state
		let launch = e.currentTarget.dataset.launch
		var newNum
			if(state==0&&launch==2){
				newNum=0
			}else
			if(state==1&&launch==2){
				newNum=1
			}else
			if(state==-1&&launch==1){
				newNum=2
			}else
			if(state==-1&&launch==2){
				newNum=3
			}
		this.setData({
			page:1,
			state:state,
			changestate:state,
			isLaunch:launch,
			dataactive:newNum,
			dataList:[],
			changetype:0,
			type:0
		})
		this.getList()
	},
	setForm() {
		this.setData({
			next:true
		})
	},
	closeForm(){
		this.setData({
			next:false
		})
	},
	pageTo(e) {
		let url = e.currentTarget.dataset.url
		wx.navigateTo({
			url: url
		})
	},
	pageTo2(e) {
		let type = e.currentTarget.dataset.type
		let id = e.currentTarget.dataset.id
		var url
		if(type==1){
			url='/pages/project/list/view?id=' + id
		}else if(type==2){
			url='/pages/project/list/view2?id=' + id + '&title=项目计划'
		}else{
			url='/pages/project/list/view2?id=' + id + '&title=工作日志'
		}
		wx.navigateTo({
			url: url
		})
	},
	onReachBottom() {
		var l=this.data.page+1
		console.log(this.data.totel)
		if(l<this.data.totel){
			this.setData({
				page:l
			})
			this.getList()
		}else{
			wx.showToast({
				title: '数据已全部加载完',
				icon: 'none'
			})
		}
	},
	
})